home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997…eptember: Technology Seed / ATS Aug-Sept '97.toast / Navigation Services SDK / Examples / Sampler / Sampler ƒ / Common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  8.1 KB  |  311 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Common.h
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #ifndef __TYPES__
  9. #include <Types.h>
  10. #endif
  11.  
  12. #ifndef __DIALOGS__
  13. #include <Dialogs.h>
  14. #endif
  15.  
  16. #ifndef __LOWMEM__
  17. #include <LowMem.h>
  18. #endif
  19.  
  20. #ifndef __TEXTUTILS__
  21. #include <TextUtils.h>
  22. #endif
  23.  
  24. #ifndef __PRINTING__
  25. #include <Printing.h>
  26. #endif
  27.  
  28. #ifndef __APPLEEVENTS__
  29. #include <AppleEvents.h>
  30. #endif
  31.  
  32. #ifndef __QDOFFSCREEN__
  33. #include <QDOffscreen.h>
  34. #endif
  35.  
  36. #include "Navigation.h"
  37.  
  38. #ifndef Common_Defs
  39. #define Common_Defs
  40.  
  41. #define kStr255Len            255        // this length is for NewPtr call, used before making a Toolbox call
  42. #define kNameLen            32        // file name length
  43.  
  44. enum checkboxstate { dechecked,checked };
  45.  
  46. #define kStrangeErr            -1
  47.  
  48. #define kActive                0
  49. #define kInactive            255
  50.  
  51. // ASCII key characters
  52. #define kCrChar                    13        // carriage return key 
  53. #define kDelChar                8        // delete key 
  54. #define kEnterChar                3        // enter char 
  55. #define kPeriodChar                46        // period char 
  56. #define kTabKey                    9        // tab char 
  57. #define kYKey                    121
  58. #define kNKey                    110
  59. #define kEscKey                    27
  60. #define kColon                    58
  61. #define kZero                    48
  62. #define kNine                    57
  63.  
  64. #define    dOK                        1
  65. #define dCancel                    2
  66.  
  67. #define kDelayTick                10        // ticks for button hiliting
  68. #define kWindowWidth            500        // width size for the text window
  69.  
  70. #define    kMaxDocumentCount        100        // maximum number of documents allowed
  71.  
  72. #define    InitialH                16
  73. #define    InitialV                42
  74.  
  75. #define    TopMargin                6
  76. #define    LeftMargin                6
  77. #define    RightMargin                6
  78. #define    BottomMargin            6
  79.  
  80. #define    ScrollResolution        12
  81.  
  82. #define kOpenRsrcID                300
  83.  
  84. // file constants
  85. #define    kFileCreator            'CPAP'
  86. #define    kFileType                'TEXT'
  87. #define kFileTypePICT            'PICT'
  88. #define kOpenRsrcType            'open'
  89.  
  90. // resource constants
  91. #define rIconSuite                128
  92. #define rAboutID                300
  93. #define iIconSuite                3
  94.  
  95. // resource string constants
  96. #define idRevertALRT            129
  97.  
  98. #define    FileStringsID            128
  99. #define    sApplicationName        1
  100.  
  101. #define    MenuStringsID            129
  102. #define    slCantUndo                1
  103. #define    slUndoDrag                2
  104. #define slRedoDrag                3
  105.  
  106. // menu resource constants
  107. #define    MenuBarID                128
  108.  
  109. #define    idAppleMenu                128
  110. #define    AboutItem                1
  111.  
  112. #define    idFileMenu                129
  113. #define    NewItem                    1
  114. #define    OpenItem                2
  115. #define    CloseItem                4
  116. #define    SaveItem                5
  117. #define SaveACopyItem            6
  118. #define    RevertItem                7
  119. //=
  120. #define DictionaryItem            9
  121. //=
  122. #define    PageSetupItem            11
  123. #define    PrintItem                12
  124. //=
  125. #define    QuitItem                14
  126.  
  127. #define    idEditMenu                130
  128. #define    iUndo                    1
  129. #define    iCut                    3
  130. #define    iCopy                    4
  131. #define    iPaste                    5
  132. #define    iClear                    6
  133. #define    iSelectAll                7
  134.  
  135. #define idUtilsMenu                131
  136. #define iSelectDir                1
  137. #define iSelectVol                2
  138. #define iCreateFolder            4
  139.  
  140. #define kScrollBarWidth         16
  141. #define kScrollBarPos             kScrollBarWidth-1
  142.  
  143. // main document:
  144. typedef struct Document
  145. {
  146.     WindowPtr        theWindow;
  147.     TEHandle        theTE;
  148.     short            docTop;
  149.     RgnHandle        hiliteRgn;
  150.     
  151.     ControlHandle    vScroll;
  152.     ControlHandle    hScroll;
  153.     short            vScrollPos;
  154.     
  155.     short            fRefNum;
  156.     short            dirty;
  157.     
  158.     Handle            undoDragText;
  159.     short            undoSelStart;
  160.     short            undoSelEnd;
  161.     
  162.     short            lastSelStart;
  163.     short            lastSelEnd;
  164.  
  165.     ParamBlockRec    fioParamBlock;            // param block for file I/O operations
  166.     Handle            fPict;
  167.     Handle            fHeader;
  168.     long            fPictLength;
  169.  
  170. } Document;
  171.  
  172.  
  173. // offscreen drawing:
  174. typedef struct WindowOffscreen
  175. {
  176.     CGrafPtr        windowPort;
  177.     GDHandle        windowDevice;
  178.     GWorldPtr        offscreenWorld;
  179. } WindowOffscreen;
  180.  
  181. WindowOffscreen* DrawOffscreen(WindowPtr theWindow);
  182.  
  183.  
  184. #define mBarHeight    (short *)0x0BAA        // Low mem global for menu bar
  185. #define EventQueue  (QHdrPtr)0x14A         // Event queue header (10 bytes)
  186. #define Mouse        ((Point*)0x830)        // processed mouse
  187. #define KeyTime     (long*)0x186        // tickcount when KEYLAST was rec'd 
  188.  
  189. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  190. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  191.  
  192. #define RectWidth(aRect) ((aRect).right - (aRect).left)
  193. #define RectHeight(aRect) ((aRect).bottom - (aRect).top)
  194.  
  195. #define Max(X, Y) ( ((X)>(Y)) ? (X) : (Y) )
  196. #define Min(X, Y) (  ((X)>(Y)) ? (Y) : (X) )
  197.  
  198. #define Pin(VALUE, MIN, MAX) ( ((VALUE) < (MIN)) ? (MIN) : ( ((VALUE) > (MAX)) ? (MAX) : (VALUE) ) )
  199.  
  200. #define kOpenPrefKey            1
  201. #define kSavePrefKey            2
  202. #define kSelectFilePrefKey        3
  203. #define kSelectFolderPrefKey    4
  204. #define kSelectVolumePrefKey    5
  205. #define kNewFolderPrefKey        6
  206.             
  207. //**************************************************************
  208.  
  209. // utility routines for detecting keydowns
  210. Boolean ModifierDown(short modifier);
  211. Boolean OptionDown(void);
  212. Boolean ShiftDown(void);
  213. Boolean CommandDown(void);
  214. Boolean ControlDown(void);
  215.  
  216. static SInt16 rnd(SInt16 max);
  217. short RandTween(short low, short high);
  218.  
  219. // file utilities:
  220. OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName, short maxPathLength, short full);
  221. Boolean FSSpecsEq(FSSpec* a, FSSpec* b);
  222. pascal void myEventProc(NavEventCallbackMessage callBackSelctor, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD);
  223.  
  224. // dialog control utilities
  225. void hiliteTheButton(DialogPtr theDialog, short whichItem);
  226. void AdornButton(DialogPtr theDialog, short whichItem);
  227. unsigned char* GetItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  228. void PokeItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  229. void PokeCtlVal(DialogPtr theDialog, short theItem, short value);
  230. void PokeCtlHilite(DialogPtr theDialog, short theItem, short value);
  231.  
  232. // string utilities
  233. OSType Str2OSType(Str255 theStr);
  234. long MyStrLen(char* s);
  235. long myStringToLong(char* s);
  236. short myStringToShort(char* s);
  237. void myStrCpy(char* dst, char* src);
  238. void myStrCat(char* dst, char* src);
  239. unsigned char* ConcatPP(unsigned char* a,unsigned char* b);
  240. char* MyP2CCopy(unsigned char* psrc,char* ctarget);
  241. unsigned char* MyC2PStr(char* theStr);
  242. char* MyP2CStr(unsigned char* theStr);
  243.  
  244. void DrawIconSuite(short resID, Rect destRect);
  245. void DebugCStr(char* msg);
  246. void AdjustCursor(Point theLoc, RgnHandle theRgn);
  247.  
  248.  
  249. // *******************************************************************
  250.  
  251. // prototypes for 'document.c'
  252. Document* NewDocument(Boolean newAsPICT);
  253. Document* IsDocumentWindow(WindowPtr theWindow);
  254. void DoUndoDrag(void);
  255. pascal void DocumentClickLoop(void);
  256. void DoActivateDocument(Document* theDocument, short activate);
  257. void DoSelectAllDocument(Document* theDocument);
  258. void UpdateWindow(Document* theDocument);
  259. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint);
  260. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart);
  261. pascal void ScrollProc(ControlHandle theControl, short theCode);
  262. void DocumentHighlightProc(void);
  263. void SizeDocWindow(Document* theDocument);
  264.  
  265. // prototypes for 'files.c'
  266. short DoSaveDocument(Document* theDocument);
  267. void DoNewDocument(Boolean newDocAsPICT);
  268. OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT);
  269.  
  270. OSErr DoOpenDocument(void);
  271. OSErr DoOpenDocumentTheOldWay(void);
  272.  
  273. OSErr SaveACopyDocument(Document* theDocument);
  274. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  275.  
  276. void DoRevertDocument(Document* theDocument);
  277. void DoRevertDocumentTheOldWay(Document* theDocument);
  278.  
  279. OSErr SaveACopyDocument(Document* theDocument);
  280. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  281.  
  282. // prototypes for 'Utilities.c'
  283. short TEIsFrontOfLine(short offset, TEHandle theTE);
  284. short TEGetLine(short offset, TEHandle theTE);
  285. short myTECut(TEHandle theTE);
  286. short myTEPaste(TEHandle theTE, short* spaceBefore, short* spaceAfter);
  287.  
  288. // prototypes for 'Offscreen.c'
  289. void DrawOnscreen(WindowOffscreen* theOffscreen);
  290.  
  291. // prototypes for 'document.c'
  292. void AdjustDocumentView(Document* theDocument);
  293. void AdjustScrollBar(Document* theDocument);
  294. void CloseDocument(Document* theDocument, Boolean quitting);
  295. void DisableUndoDrag(void);
  296. void AddText(Document* theDocument, Ptr text, long len);
  297.  
  298. // prototypes for 'drag.c'
  299. short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn);
  300.  
  301. // prototypes for 'menu.c'
  302. void AdjustMenus(void);
  303. void DoMenuCommand(long select);
  304.  
  305. // prototypes for 'event.c'
  306. void EventLoop(void);
  307. pascal OSErr MyHandleOAPP(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  308. pascal OSErr MyHandleODOC(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  309. pascal OSErr MyHandleQUIT(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  310.  
  311. #endif // Common_Defs